package hash.t454;

import java.util.HashMap;
import java.util.Map;

public class One {

    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {

        // 我靠，官方题解也是遍历四个数组

        int result = 0;

        Map<Long, Integer> map = new HashMap();

        for (int i : nums1) {
            for (int j : nums2) {
                Long sum = (long) (i + j);
                map.put(sum, map.getOrDefault(sum, 0) + 1);
            }
        }

        for (int k : nums3) {
            for (int l : nums4) {
                Long sum = -(long) (k + l);
                result += map.getOrDefault(sum, 0);
            }
        }

        return result;
    }
}
